<?php

	// TITLE: Interested_in AUTO MODEL
	// FILE: scaffolding/model/interested_in.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createInterestedIn = function($con, $interestedIn) {
		$sql = 'INSERT INTO interested_in (volunteer_id, interest_id) VALUES (';
		$sql .= $interested_in->getVolunteerId() . ', ';
		$sql .= $interested_in->getInterestId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readInterestedIn = function($con, $id) {
		$sql = 'SELECT * FROM interested_in WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$interestedIn = new InterestedIn();
			$interestedIn->setVolunteerId($dbio->select($readVolunteer(result[0])));
			$interestedIn->setInterestId($dbio->select($readInterest(result[1])));
		} else {
			$interestedIn = false;
		}
		return $interestedIn;
	};

	$updateInterestedIn = function($con, $interestedIn) {
		$sql = 'UPDATE interested_in SET ';
		$sql .= 'volunteer_id = ' . $interested_in->getVolunteerId() . ', ';
		$sql .= 'interest_id = ' . $interested_in->getInterestId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteInterestedIn = function($con, $id) {
		$sql = 'DELETE FROM interested_in WHERE volunteer_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listInterestedIn = function($con) {
		$sql = 'SELECT * FROM interested_in';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$interestedIns = array();
			while ($result = mysqli_fetch_array($results)) {
				$interestedIn = new InterestedIn();
				$interestedIn->setVolunteerId($dbio->select($readVolunteer(result[0])));
				$interestedIn->setInterestId($dbio->select($readInterest(result[1])));
				$interestedIns[] = interestedIn;
			}// end while
		} else {
			$interestedIns = false;
		}
		return $interestedIns;
	};

